from py_stealth import *

resource_box = 0x400E4A95
target_box = (0x40E18733, 0x40E17644, 0x405E726C, 0x406737F6)


def lock_box(target):
    UseObject(target)
    Wait(1000)
    FindType(0x100E, target)
    UseObject(FindItem())
    WaitForTarget(1000)
    TargetToObject(target)


def unlock_box(target):
    if FindType(0x14FC, Backpack()) > 0:
        UseObject(FindItem())
        WaitForTarget(1000)
        TargetToObject(target)
    else:
        load_lock_pick()


def load_lock_pick():
    UseObject(resource_box)
    CheckLag(3000)
    Wait(1000)
    if FindType(0x14FC, resource_box) > 0:
        MoveItem(FindItem(), 66, Backpack(), 0, 0, 0)
        CheckLag(3000)
        Wait(1000)
    else:
        AddToSystemJournal('没有开锁器了')
        Disconnect()
        exit(0)


def check_lock_pick():
    if FindType(0x14FC, Backpack()) < 0:
        load_lock_pick()


_targetValue = 95
_currentSkillValue = 0
while _currentSkillValue < _targetValue:
    _currentSkillValue = GetSkillValue('Lockpicking')
    check_lock_pick()
    target = 0

    if TargetPresent():
        CancelWaitTarget()
    if _currentSkillValue < 25:
        AddToSystemJournal('需要学习开锁技能到25点以上')
    elif _currentSkillValue < 40:
        target = target_box[0]
    elif _currentSkillValue < 55:
        target = target_box[1]
    elif _currentSkillValue < 67:
        target = target_box[2]
    elif _currentSkillValue < 95:
        target = target_box[3]

    if GetTooltip(target).find('items') > 0:
        lock_box(target)
    else:
        unlock_box(target)
    Wait(3000)
